//
//  LSBaseViewController.m
//  听说弱点强化训练
//
//  Created by 盛超 on 2018/8/18.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSBaseViewController.h"

@interface LSBaseViewController ()<LGTokenListenerDelegate>

@end

@implementation LSBaseViewController

- (UIStatusBarStyle)preferredStatusBarStyle {
    return _statusBarStyle;
}

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle {
    _statusBarStyle = statusBarStyle;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    // 禁用返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LGTokenListener *listen = [LGTokenListener  shareTokenListener];
    listen.delegate = self;
    [listen start];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.statusBarStyle = UIStatusBarStyleLightContent;
    
    [self.view addSubview:self.navBarView];
    [self.navBarView addSubview:self.backBtn];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 懒加载
- (UIImageView *)navBarView {
    if (!_navBarView) {
        _navBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kNavgationBar)];
        _navBarView.image = [UIImage imageNamed:@"content_nav"];
        _navBarView.userInteractionEnabled = YES;
    }
    return _navBarView;
}

- (UIButton *)backBtn {
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(0, 20, 40, 40);
        [_backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _backBtn;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavgationBar, kWidth, kHeight-kNavgationBar) style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

#pragma mark - Public
- (void)backAction:(UIButton *)sender {
    
}

#pragma mark - Private


#pragma mark - LGTokenListenerDelegate
//监听登录状态
- (void)tokenDidInvalid {
    Authentication *auth = [[Authentication alloc] init];
    NSLog(@"%@",self);
    [auth loginWithAlertViewWithCurrentController:self titleName:@"智能备考学习" success:^{
        NSLog(@"登录成功");
    } popResult:^{
        // 退出项目。
        UIWindow *window =  [UIApplication sharedApplication].keyWindow;
        [UIView animateWithDuration:0.5f animations:^{
            window.alpha = 0;
            window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);
        } completion:^(BOOL finished) {
            exit(0);
        }];
    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [UITableViewCell new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
